//Sun May  2 10:48:19 CDT 2010
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class GirlsAndBoys
{
public:
	int sortThem(string row)
	{
		str1 = row;
		sort(str1.begin(), str1.end());
		int count1 = 0;
		int count2 = 0;
		int idx = 0;
		while (str1[idx] == 'B')
		{
			idx++;
		}
		int mid1 = idx - 1;
		int mid2 = row.size() - idx - 1;
		int i;
		for (i = 0; i <= mid1; i++)
		{
			if (row[i] == 'G')
			{
				count1 += (mid1- i);
			}

		}
		for (; i < row.size(); i++)
		{
			if (row[i] == 'B')
			{
				count1 += (i - mid1);
			}

		}
		for (i = 0; i <= mid2; i++)
		{
			if (row[i] == 'B')
			{
				count2 += (mid2 - i);
			}
		}
		for (; i < row.size(); i++)
		{
			if (row[i] == 'G')
			{
				count2 += (i - mid2);
			}
		}
		return min(count1, count2);
	}
	string str1;
};
